# Copyright (c) 2019 Presto Labs Pte. Ltd.
# Author: jaewon

from experimental.prophet.graph import graph
from experimental.prophet.graph.util import to_data_type_proto


def cast(value, dtype):
  from experimental.prophet.graph.variable import as_variable
  value = as_variable(value)
  if to_data_type_proto(value.dtype) == to_data_type_proto(dtype):
    return value
  node = graph.create_node('Cast', [value],
                           attrs={
                               'dtype': to_data_type_proto(value.dtype),
                               'to_dtype': to_data_type_proto(dtype)
                           })
  return node.outputs[0]
